﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tao.OpenGl;

namespace GameLoop
{   
    public partial class GameLoopForm : Form
    {
        private bool _fullScreen = false;
        private FastLoop _fastLoop;
        /// <summary>
        /// Initializes the Class FastLoop
        /// the component and the OpenGL context.
        /// </summary>
        public GameLoopForm()
        {
            _fastLoop = new FastLoop(GameLoop);
            InitializeComponent();
            _openGLControll.InitializeContexts();
            if (_fullScreen)
            {
                FormBorderStyle = FormBorderStyle.None;
                WindowState = FormWindowState.Maximized;
            }
        }
        /// <summary>
        /// Implements the Game Loop and renders
        /// a simple RGB triangle that rotates over 
        /// the three axis. 
        /// </summary>
        /// <param name="elapsedTime"></param>
        void GameLoop(double elapsedTime)
        {
            Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Gl.glRotated(10 * elapsedTime, 0.5, 1, 0.8);
            Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
            {
                Gl.glColor3d(1.0, 0.0, 0.0); 
                Gl.glVertex3d(-0.5, 0, 0); 
                Gl.glColor3d(0.0, 1.0, 0.0); 
                Gl.glVertex3d(0.5, 0, 0);
                Gl.glColor3d(0.0, 0.0, 1.0); 
                Gl.glVertex3d(0, 0.5, 0);
            }
            Gl.glEnd();
            Gl.glFinish();
            _openGLControll.Refresh();
        }
    }
}
